package action;

import infrastructure.IDossier;
import mappers.InfractionMapper;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class VisualiserDossierAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	// dossier selection grace au id
	private IDossier dossierSelectionne;
	private InfractionMapper infractionDAO;

	public void setInfractionDAO(InfractionMapper infractionDAO) {
		this.infractionDAO = infractionDAO;
	}

	public IDossier getDossierSelectionne() {
		return dossierSelectionne;
	}

	public void setDossierSelectionne(IDossier dossierSelectionne) {
		this.dossierSelectionne = dossierSelectionne;
	}

	public String getDossierSession() {
		Object sessionDossier = ServletActionContext.getRequest().getSession()
				.getAttribute("DossierCourant");
		if (sessionDossier != null) {
			if (sessionDossier instanceof IDossier) {
				setDossierSelectionne((IDossier) sessionDossier);
				dossierSelectionne.setInfractions(infractionDAO
						.getByDossierID(dossierSelectionne.getId()));
			} else {
				return ERROR;
			}
		}

		return SUCCESS;
	}
}
